import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {fileURLToPath, URL} from 'node:url'


import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'


// https://vite.dev/config/
export default defineConfig({
    plugins: [vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),],
    server: {
        // 配置代理服务器
        proxy: {
            '/api': {
                // 真正发送请求的地址
                target: 'https://api.uomg.com/api/rand.qinghua',
                // 开启跨域请求
                changeOrigin: true,
                // 在请求路径中去除 /api路径
                rewrite: (path) => path.replace(/^\/api/, '')
            }
        }
    },
    // 作用我们将.src 根目录转换成@
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    }
})
